home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / appl / napsaterm / napsaterm.c < prev    next >
C/C++ Source or Header  |  1994-05-18  |  6KB  |  253 lines

  1. RCS_ID_C="$Id: napsaterm.c,v 3.8 1994/05/18 00:20:08 ppessi Exp $";
  2. /*
  3.  * napsaterm.c --- NapsaTerm terminal emulator 
  4.  *
  5.  * Author: ppessi <Pekka.Pessi@hut.fi>
  6.  *
  7.  * Copyright (c) 1993 Pekka Pessi
  8.  *
  9.  * Created      : Mon Oct 18 17:23:37 1993 ppessi
  10.  * Last modified: Tue May 17 03:15:11 1994 ppessi
  11.  *
  12.  * Copyright 1988, 1989 Chris Newman
  13.  * All Rights Reserved
  14.  * Permission is granted to copy, modify, and use this as long
  15.  * as this notice remains intact.  This is a nifty program.
  16.  *
  17.  * Parts of this program were swiped from Joe Keane's jterm, other parts
  18.  * were swiped from ITC's h19 terminal, and still others from gnu-emacs eterm.
  19.  *
  20.  * DISCLAIMER: the author (and maintainer) of this program is not responsible
  21.  * for any damage or other problems caused by it.
  22.  *
  23.  * $Log: napsaterm.c,v $
  24.  * Revision 3.8  1994/05/18  00:20:08  ppessi
  25.  * *** empty log message ***
  26.  *
  27.  * Revision 3.7  1994/05/14  14:10:48  ppessi
  28.  * Removed separate tektronix version
  29.  *
  30.  * Revision 3.6  1994/05/14  10:58:42  ppessi
  31.  * Updated for telnet code.  Moved revision file include here from
  32.  * global include file "nifty.h".
  33.  *
  34.  * Revision 3.4  1994/05/12  10:53:05  ppessi
  35.  * Merged changes from Napsaterm 3.5 by R. Knop
  36.  *
  37.  */
  38.  
  39. #include <stdlib.h>
  40. #include "nifty.h"
  41. #include "amiga.h"
  42. #include "display.h"
  43. #include "nio.h"
  44. #include "napsaprefs.h"
  45. #include <string.h>
  46. #include <stdarg.h>
  47. #include <signal.h>
  48.  
  49. #include "napsaterm_rev.h"
  50.  
  51. const char ProgName[] = VERS;
  52. const char version[] = VERSTAG;
  53. const char copyright[] =
  54.   "Napsaterm, terminal emulator for AmiTCP/IP, Internation version 3\n"
  55.   "Copyright © 1991, 1993 Pekka Pessi and AmiTCP/IP Group, "
  56.   "<amitcp-group@hut.fi>,\n"
  57.   "Helsinki University of Technology, Finland.\n"
  58.   "For full copyright information see supporting documentation.\n"
  59.   "Original NiftyTerm © Copyright 1990 by Chris Newman and Todd Williamson.\n"
  60.   "All Rights Reserved.\n"
  61.   "This is a nifty program.\n";
  62.  
  63. /* Non-standard libraries */
  64. struct GfxBase *GfxBase = NULL;
  65. struct IntuitionBase *IntuitionBase = NULL;
  66. struct DiskfontBase *DiskfontBase = NULL;
  67. struct Library *IconBase = NULL;
  68.  
  69. struct Library *TimerBase = NULL;
  70. struct MsgPort *timeport = NULL;
  71. struct timerequest *timereq = NULL;
  72.  
  73. BPTR logfile = NULL;    /* current log file */
  74.  
  75. BOOLEAN started_from_workbench = FALSE;
  76.  
  77. char MEMORY_ERROR_MSG[] = "Out of memory";
  78.  
  79. /* This allows terminal answerback messages
  80.  */
  81. int write_to_tty(char *buf, int    count)
  82. {
  83.     if (iotype != stdio)
  84.     return (nwrite(buf, count));
  85.     dsputs(buf);
  86.     return (count);
  87. }
  88.  
  89. void amigainit(void)
  90. {
  91.     GfxBase = (struct GfxBase *)
  92.       OpenLibrary("graphics.library", 37L);
  93.     IntuitionBase = (struct IntuitionBase *)
  94.       OpenLibrary("intuition.library", 37L);
  95.     DiskfontBase = (struct DiskfontBase *)
  96.       OpenLibrary("diskfont.library", 37L);
  97.     IconBase = OpenLibrary("icon.library", 37L);
  98.  
  99.     timeport = CreateMsgPort();
  100.     if (timeport) {
  101.     timereq = (void *)CreateIORequest(timeport, sizeof(*timereq));
  102.     }
  103.     if (!GfxBase || !IntuitionBase || !DiskfontBase || !IconBase
  104.     || !timeport || !timereq) {
  105.         fatalError("Problem during initialization.\n"
  106.            "A needed library or resource was not found.\n");
  107.     }
  108.  
  109.     if (OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *)timereq, 0)) {
  110.         fatalError("Problem opening " TIMERNAME);
  111.     } 
  112.     TimerBase = (struct Library *)timereq->tr_node.io_Device;
  113.     timereq->tr_node.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
  114. }
  115.  
  116. void amigaquit(void)
  117. {
  118. #ifdef TEKTRONICS       /*Added RKNOP 940328*/
  119.     closetekwin();
  120. #endif
  121.     if (timereq) {
  122.     if (TimerBase) {
  123.         if (!CheckIO(timereq)) {
  124.         AbortIO(timereq);
  125.         WaitIO(timereq);
  126.         }
  127.         CloseDevice((struct IORequest *)timereq), TimerBase = NULL;
  128.     }
  129.         DeleteIORequest((struct IORequest *)timereq), timereq = NULL;
  130.     }
  131.  
  132.     if (timeport) 
  133.     DeleteMsgPort(timeport), timeport = NULL;
  134.  
  135.     nclose();
  136.  
  137.     if (IconBase) 
  138.     CloseLibrary(IconBase), IconBase = NULL;
  139.     if (GfxBase) 
  140.     CloseLibrary((struct Library*)GfxBase), GfxBase = NULL;
  141.     if (IntuitionBase) 
  142.     CloseLibrary((struct Library*)IntuitionBase), IntuitionBase = NULL;
  143.     if (DiskfontBase) 
  144.     CloseLibrary((struct Library*)DiskfontBase), DiskfontBase = NULL;
  145.     if (logfile) 
  146.     Close(logfile), logfile = NULL;
  147. }
  148.  
  149. static void iopoll(void)
  150. {
  151.     int n;
  152.  
  153.     if ((n = nnread(iobuf, sizeof(iobuf))) > 0) {
  154.     if (logfile != (BPTR) NULL && n && (Write(logfile, iobuf, n) != n)) {
  155.         Close(logfile);
  156.         logfile = (BPTR) NULL;
  157.         PutStr("Error writing to log file\n");
  158.     }
  159.     termout(iobuf, n);
  160.     } else if (n < 0) {
  161.     /* IO error? EOF? let's quit */
  162.     if (np.wait_to_end) {
  163.         waitToEnd();
  164.     }
  165.     dsquit();
  166.     amigaquit();
  167.     exit(0);
  168.     }
  169. }
  170.  
  171. /*
  172.  * niftyterm entry point
  173.  */
  174. int main(int argc, char **argv)
  175. {
  176.     long winmask, timemask, mask, iomask;
  177.  
  178.     /* Disable ^C signaling */
  179.     signal(SIGINT, SIG_IGN);
  180.  
  181.     started_from_workbench = argc == 0;
  182.  
  183.     amigainit();
  184.  
  185.     if (started_from_workbench) {
  186.       argv = parsewbargs((struct WBStartup *)argv); 
  187.     } else {
  188.       argv = parseargs(argv);
  189.     }
  190.  
  191.     if (np.stdio) {
  192.     iotype = stdio;
  193.     if (np.show_version) {
  194.         PutStr(version);
  195.         PutStr(copyright);
  196.     }
  197.     } else {
  198.     /*
  199.      * Set IO type depending of the device name
  200.      */
  201.     if (np.device) {
  202.         if (!stricmp(np.device, "dnet")) {
  203.         iotype = dnet;
  204.         } else if (!stricmp(np.device, "net")) {
  205.         iotype = rlogin;
  206.         } else if (!stricmp(np.device, "telnet")) {
  207.         iotype = telnet;
  208.         } else {
  209.         iotype = serial;
  210.         }
  211.     }
  212.     }
  213.  
  214.     /* Use ANSI linefeed mode */
  215.     np.ansi_LNM = iotype == serial;
  216.  
  217.     ninit(iotype);
  218.  
  219.     if (np.logname)
  220.     logfile = Open(np.logname, MODE_NEWFILE);
  221.  
  222.     dsinit();
  223.  
  224.     iomask = nopen(argv); 
  225.     winmask = dsmask();
  226.     timemask = dsflashinit();
  227.  
  228.     for (;;) {
  229. #ifdef TEKTRONICS               /*added RKNOP 940328*/
  230.         mask = Wait(iomask | winmask | tekwinmask | timemask);
  231. #else
  232.     mask = Wait(iomask | winmask | timemask);
  233. #endif
  234.  
  235.     if (mask & timemask) {
  236.         dscheckflash();
  237.     }
  238.     if (mask & winmask) {
  239.         dspoll();
  240.     }
  241. #ifdef TEKTRONICS           /*added RKNOP 940121*/
  242.         if (mask & tekwinmask) {
  243.            tekpoll();
  244.         }
  245. #endif
  246.     if (mask & iomask) {
  247.         iopoll();
  248.         }
  249.     }    
  250.     /*NOTREACHED*/
  251. }
  252.  
  253.